

import java.util.Date;

import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.Mongo;
import com.mongodb.WriteResult;


public class Test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		
		
		try {
			long t1 = System.currentTimeMillis();
			Mongo m = new Mongo();
			long t2 = System.currentTimeMillis();
			DB db = m.getDB("test");
			
			DBCollection coll = db.getCollection("users");
			
//			for (int i = 100001; i <= 1000000; i++) {
				BasicDBObject doc = new BasicDBObject();
				doc.put("username", "zhangleidate");
				doc.put("password", System.currentTimeMillis());
				doc.put("created_at", new Date());
				WriteResult wrs = coll.insert(doc);
//				System.out.println(i + "-" + wrs.getError());
//			}
			
			BasicDBObject query = new BasicDBObject();
			query.put("username", "zhangleidate");
			
			
			DBCursor cur = coll.find(query);
			
			
			if (cur.hasNext()) {
				
				System.out.println(cur.next() + "[" + (t2-t1) + "ms]");
			}
			
			System.out.println("=====================");
			
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
